package com.msf.frametest.components;

import com.msf.frametest.utils.UIUtil;

import javax.swing.*;
import java.awt.*;

public class InnerFrame extends JFrame {

    private UIUtil uiUtil = new UIUtil();

    public InnerFrame() {
        super("内部Frame");
        try {
            getContentPane().setLayout(new FlowLayout());
            getContentPane().add(new JLabel("内部测试Frame"));

            JButton modalButton = uiUtil.createButton("模态对话框", e -> { showModalDialog(); });
            JButton nonModalButton = uiUtil.createButton("非模态对话框", e -> { showNonModalDialog(); });

            getContentPane().add(modalButton);
            getContentPane().add(nonModalButton);

            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setLocationRelativeTo(null);
            setSize(300, 400);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void showModalDialog() {
        ModalDialog modalDialog = new ModalDialog(this);
        modalDialog.setVisible(true);
    }

    private void showNonModalDialog() {
        NonModalDialog nonModalDialog = new NonModalDialog(this);
        nonModalDialog.setVisible(true);
    }
}
